package components;

import entities.Creature;
import entities.Entity;
import game.Collision;
import game.Level;

public class DamageOnTouchComponent extends EntityComponent {

	private Class<? extends Creature>[] creatureClasses;
	private int damage;

	public DamageOnTouchComponent(Entity e, int damage,
			Class<? extends Creature>... creatureClasses) {
		super(e);
		this.creatureClasses = creatureClasses;
		this.damage = damage;
	}

	@Override
	public void tick(float dt) {
		//Collision testing
		Creature creature;
		Level l = entity.getLevel();
		for (Class<? extends Creature> c : creatureClasses) {
			for (Collision<Entity> collision : l.getCollisions(entity, c)) {
				creature = (Creature) collision.getColldingEntity();
				if (collision.isCollision()) {
					creature.takeDamage(damage, entity);
				}
			}
		}
	}

}
